package org.paboo.chart.pdf417;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.pdf417.PDF417Writer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.Map;

public class ZxingUtil {
    private final static Logger log = LogManager.getLogger(ZxingUtil.class);

    public static BitMatrix encode(Pdf417Entity p) throws WriterException {
        Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, p.getEncoding());
        hints.put(EncodeHintType.ERROR_CORRECTION, p.getErrorCorrectionLevel());
        hints.put(EncodeHintType.MARGIN, p.getMargin());
        return new PDF417Writer().encode(p.getData(), BarcodeFormat.PDF_417, p.getWidth(), p.getHeight(), hints);
    }
}
